<template>
  <el-upload
    :disabled="isXQ"
    class="avatar-uploader"
    action=""
    :show-file-list="false"
    :before-upload="beforeAvatarUpload"
  >
    <img v-if="shop_avatar" :src="shop_avatar" class="avatar">

    <i v-else class="el-icon-plus avatar-uploader-icon" />
  </el-upload>
</template>

<script>
import hyp from './hyp'
export default {
  props: {
    shop_avatar: {
      type: String,
      default() {
        return ''
      }
    },
    isXQ: {
      type: Boolean,
      default() {
        return true
      }
    }
  },
  data() {
    return {
      imageUrl: ''
    }
  },
  methods: {
    beforeAvatarUpload(file) {
      const formData = new FormData()
      formData.append('file', file)
      hyp.post('/upload', formData).then((res) => {
        this.$emit('img_upload', res.data.url)
      })
    }
  }
}
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 120px;
  height: 120px;
  display: block;
}
.el-icon-plus.avatar-uploader-icon {
  display: flex;
  justify-content: center;
  align-items: center;
}

</style>
